package com.aiyige.utils.prefs;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class Prefs {
	private final static String VERSION = "_version";
	private final String name;
	private SharedPreferences preferences;

	public Prefs(Context context, String name) {
		this.name = name;
		preferences = context.getSharedPreferences(name, Context.MODE_PRIVATE);
	}

	public String getName() {
		return name;
	}

	public int getVersion() {
		return getInt(VERSION, 0);
	}

	public void setVersion(int version) {
		putInt(VERSION, version);
	}

	public boolean getBoolean(String key, boolean defValue) {
		return preferences.getBoolean(key, defValue);
	}

	public void putBoolean(String key, boolean value) {
		Editor editor = preferences.edit();
		editor.putBoolean(key, value);
		editor.commit();
	}

	public int getInt(String key, int defValue) {
		return preferences.getInt(key, defValue);
	}

	public void putInt(String key, int value) {
		Editor editor = preferences.edit();
		editor.putInt(key, value);
		editor.commit();
	}

	public long getLong(String key, long defValue) {
		return preferences.getLong(key, defValue);
	}

	public void putLong(String key, long value) {
		Editor editor = preferences.edit();
		editor.putLong(key, value);
		editor.commit();
	}

	public float getFloat(String key, float defValue) {
		return preferences.getFloat(key, defValue);
	}

	public void putFloat(String key, float value) {
		Editor editor = preferences.edit();
		editor.putFloat(key, value);
		editor.commit();
	}

	public String getString(String key, String defValue) {
		return preferences.getString(key, defValue);
	}

	public void putString(String key, String value) {
		Editor editor = preferences.edit();
		editor.putString(key, value);
		editor.commit();
	}

}
